package com.gitee.magic.context.editor;

import com.gitee.magic.context.RestConverterEditor;
import com.gitee.magic.core.converter.AbstractConverterEditor;
import com.gitee.magic.core.json.JsonObject;

/**
 * @author start
 */
@SuppressWarnings("deprecation")
public class JsonObjectConverterEditor extends AbstractConverterEditor<JsonObject> {

	public JsonObjectConverterEditor(Class<?> prototype) {
		super(prototype);
	}

	@Override
	public void restore(Object value) {
		if (value != null) {
			JsonObject json=(JsonObject)value;
			setSource(json);
			setValue(RestConverterEditor.converterObject(getPrototype(), json));
		}
	}

	@Override
	public JsonObject converter() {
		if (getValue() == null) {
			return null;
		}
		return RestConverterEditor.converterJsonObject(getValue());
	}

	@Override
	public Object getSource() {
		return converter();
	}

}
